<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>父子组件的数据传递</title>
    <script src="./vue.js"></script>
</head>
<body>

    <div id="root">
        <counter :count="2" @inc="handleIncrease"></counter>
        <counter :count="3" @inc="handleIncrease"></counter>
        <div>{{total}}</div>
    </div>

    <script>


        var counter = {
            props: ['count'],
            data: function () {
                return {
                    number:  this.count
                }
            },
            template: '<div @click="handleClick">{{number}}</div>',
            methods: {
                handleClick: function () {
                    this.number =  this.number + 2
                    this.$emit('inc', 2)
                }
            }
        }
        var vm = new Vue({
            el: "#root",
            data: {
                total: 5
            },
            components: {
                counter: counter
            },
            methods: {
                handleIncrease: function (step) {
                   this.total += step
                }
            }
        })
    </script>
</body>
</html>